package cevent.source.cloudcenter.business.controller.admin;

import cevent.source.cloudcenter.server.dto.SiteSetDto;
import cevent.source.cloudcenter.server.dto.PageDto;
import cevent.source.cloudcenter.server.dto.ResponseDataDto;
import cevent.source.cloudcenter.server.service.SiteSetService;
import cevent.source.cloudcenter.server.util.ValidatorUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.List;

/**
 * @author cevent
 * @description 站点设置表控制层
 */
@RestController
@RequestMapping("/admin/siteSet")
public class SiteSetController {
    private static final Logger LOG = LoggerFactory.getLogger(SiteSetController.class);
    //AOP日志环绕
    public static final String BUSINESS_NAME="模块管理 站点设置表";
    @Resource
    private SiteSetService siteSetService;

    //1.dto-siteSet获取
    @RequestMapping("/dtoList")
    public List<SiteSetDto> getDtoList() {
        return siteSetService.siteSetDtoList();
    }


    /*2.前端分页设置，后端pageInfo处理
    前端传参方式一：表单方式--》formData 前端：直接传对象   后端参数：(Dto对象)
    前端传参方式二：流的方式--》data{param1:value1,param2:vlaue2}  后端参数：(@RequestBody Dto dto对象)
     */
    @PostMapping("/pageList")
    public ResponseDataDto list(@RequestBody PageDto pageDto) {
        LOG.info("查看controller的pageDto：{}", pageDto);
        ResponseDataDto responseData = new ResponseDataDto();
        siteSetService.getSiteSetPageDtoList(pageDto);
        responseData.setResponseData(pageDto);
        return responseData;
    }

    //3.新增，流方式传参，加入@RequestBody
    @PostMapping("/save")
    public ResponseDataDto save(@RequestBody SiteSetDto siteSetDto) {
        LOG.info("传入的siteSet DTO：{}", siteSetDto);

        ValidatorUtil.requiredLength(siteSetDto.getName(), "站点名称", 3, 255);
        ValidatorUtil.requiredLength(siteSetDto.getSeoTitle(), "SEO标题", 3, 255);
        ValidatorUtil.requiredLength(siteSetDto.getSeoDescription(), "seo描述", 3, 255);
        /*ValidatorUtil.requiredLength(siteSetDto.getDomainName(), "域名配置", 3, 255);
        ValidatorUtil.requiredLength(siteSetDto.getContact(), "联系方式", 3, 255);
        ValidatorUtil.requiredLength(siteSetDto.getMobile(), "手机号", 3, 255);
        ValidatorUtil.requiredLength(siteSetDto.getEmail(), "邮箱", 3, 255);
        ValidatorUtil.requiredLength(siteSetDto.getAddress(), "地址", 3, 255);
        ValidatorUtil.requiredLength(siteSetDto.getQqNum(), "QQ号码", 3, 255);
        ValidatorUtil.requiredLength(siteSetDto.getWechatNum(), "微信", 3, 255);*/
        ResponseDataDto responseData = new ResponseDataDto();
        siteSetService.save(siteSetDto);
        responseData.setResponseData(siteSetDto);
        return responseData;
    }

    /**
     * 指定请求的格式为Delete
     * 4.删除模块，如果为多个参数，就定义多个/{param}/{param}
     */
    @DeleteMapping("/del/{uniId}")
    public ResponseDataDto del(@PathVariable String uniId) {
        LOG.info("传入的siteSet uniId：{}", uniId);
        ResponseDataDto responseData = new ResponseDataDto();
        siteSetService.delete(uniId);
        return responseData;
    }

}
